/**
 * 
 */
package com.ai.dmc.index.service.indicatorcommon;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ai.dmc.index.base.impl.base.BaseServiceImpl;
import com.ai.dmc.index.common.data.PubConstant;
import com.ai.dmc.index.common.exception.BusinessException;
import com.ai.dmc.utils.string.StringUtil;
import com.ai.frame.bean.InputObject;
import com.ai.frame.bean.OutputObject;
import com.ai.frame.logger.Logger;
import com.ai.frame.logger.LoggerFactory;

/**
 * Title：  指标头部搜索和菜单展示
 * Description：  指标头部搜索和菜单展示
 * Copyright：Copyright (c) 2009
 * Company：北京亚信智慧数据科技有限公司
 * @author lg, 2016年3月1日
 * @version 1.0
 */
public class IndicatorCommonServiceImpl extends BaseServiceImpl  {
    // 定义对应Mapper文件的命名空间
    private static final String NAMESPACE = "IIndicatorCommonDao.";
    
//    private IPrivilegeService privilege;
//    public void setPrivilege(IPrivilegeService privilege) {
//        this.privilege = privilege;
//    }
        
    public static Logger log = LoggerFactory.getServiceLog(IndicatorCommonServiceImpl.class);
 //   @Override
   /* public void queryIdxHeadSearch(InputObject inputObject, OutputObject outputObject) throws BusinessException {
        int totalRecord = 0;
        totalRecord = this.getBaseDao().getTotalCount(NAMESPACE + "selectIndicatorsInfoTotalCount", inputObject.getParams());
        List<Map<String, String>> indicatorsInfoList = this.getBaseDao().queryForPageList(
                    NAMESPACE + "selectIndicatorsInfo", inputObject.getParams());
        Map<String, String> totalMap = new HashMap<String, String>();
        totalMap.put("dataTotal", String.valueOf(totalRecord));
        outputObject.setBean(totalMap);
        outputObject.setBeans(indicatorsInfoList);
    }

    @SuppressWarnings("unchecked")
    @Override
    public void queryIdxHeadMemu(InputObject inputObject, OutputObject outputObject) throws BusinessException {
        try {
//        List<String> privil = privilege.getMenu(inputObject);
        List<Map<String,Object>> memuResultList = new ArrayList<Map<String,Object>>();
        // 查询一级菜单
        List<Map<String,String>> memuOneList = this.getBaseDao().queryForList(NAMESPACE+"queryIdxHeadMemuOne", inputObject.getParams());
        //过滤权限菜单
//        filterDimAuthor(privil,memuOneList);
        if(null!=memuOneList&&memuOneList.size()>0){
            for(Map<String,String> memuOneMap:memuOneList){
                Map<String,Object> resultMap = new HashMap<String,Object>();
                resultMap.putAll(memuOneMap);
                String memuOneUrl = String.valueOf(memuOneMap.get("modeUrl"));
                if(StringUtil.isEmpty(memuOneUrl)||PubConstant.RESULT_NULL.equals(memuOneUrl)){
                    //查询二级菜单
                    List<Map<String,String>> memuTwoList = this.getBaseDao().queryForList(NAMESPACE+"queryIdxHeadMemuTwo", memuOneMap);
                    //过滤权限菜单
//                    filterDimAuthor(privil,memuTwoList);
                    List<Map<String,Object>> memuResultListTemp = new ArrayList<Map<String,Object>>();//暂存二级菜单
                    if(null != memuTwoList && memuTwoList.size() >0){
                        for(Map<String,String> memuTwoMap:memuTwoList){
                            Map<String,Object> resultMapTwo = new HashMap<String,Object>();
                            resultMapTwo.putAll(memuTwoMap);
                            String memuTwoUrl = String.valueOf(memuOneMap.get("modeUrl"));
                            //查询三级菜单
                            if(StringUtil.isEmpty(memuTwoUrl)||PubConstant.RESULT_NULL.equals(memuTwoUrl)){
                                List<Map<String,String>> memuThreeList = this.getBaseDao().queryForList(NAMESPACE+"queryIdxHeadMemuTwo", memuTwoMap);
                                //过滤权限菜单
//                                filterDimAuthor(privil,memuThreeList);
                                resultMapTwo.put("child", memuThreeList);
                            }else{
                                resultMapTwo.put("child", "");
                            }
                            memuResultListTemp.add(resultMapTwo);
                        }
                    }
                    resultMap.put("child", memuResultListTemp);
                }else{
                    resultMap.put("child", "");
                }
                memuResultList.add(resultMap);
            }
        }
        //查询底部信息 beans
        List<Map<String,String>> memuFootList = this.getBaseDao().queryForList(NAMESPACE+"queryIdxFootMemuInfo", inputObject.getParams());
        //版权信息 bean
        Map<String,String> copyrightMap = (Map<String,String>)this.getBaseDao().queryForObject(NAMESPACE+"queryIdxCopyrightInfo", inputObject.getParams());
        outputObject.setBeans(memuFootList);
        outputObject.setBean(copyrightMap);
        outputObject.setObject(memuResultList);
        } catch (Exception e) {
            e.printStackTrace();
            BusinessException exception = new BusinessException(e.getMessage());
            throw exception;
        }
    }
    
    *//**
     * 
     * TODO
     * @param memuList 
     * @param privil 
     *//*
    private void filterDimAuthor(List<String> privil, List<Map<String, String>> memuList){
        for(int i=0;i<memuList.size();i++){
            if(!privil.contains(memuList.get(i).get("modeId"))){
                memuList.remove(i);
                i--;
            }
        }
    }*/
}
